<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加内容</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layui/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
        .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}


        .layui-form-label{
            width: 90px;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <label class="layui-form-label required">标题</label>
        <div class="layui-input-block">
            <input type="text" id="titie" name="titie" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入标题" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">内容</label>
        <div class="layui-input-block">
            <textarea id="content" name="content" style="display: none;"></textarea>
<%--            <input type="text" name="content" lay-verify="required" lay-reqtext="内容不能为空" placeholder="请输入内容" value="" class="layui-input">--%>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确定</button>
        </div>
    </div>
</div>
<script src="/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'upload', 'layedit'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            layedit = layui.layedit,
            $ = layui.$;

        // 富文本
        layedit.set({
            uploadImage: {
                url: '/System/file', //接口url
                type: 'post' //默认post
            }
        });


        let htmlTag = layedit.build('content'); //建立编辑器

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            var titie = $("#titie").val();

            $.ajax({
                url: '/System/helpSave',
                type: 'post',
                data: {"content" : layedit.getContent(htmlTag), "titie" : titie},
                dateType: 'json',
                success: function (result) {
                    if (result.code == '0') {
                        // 关闭弹出层
                        layer.close();
                        // 刷新上一层页面
                        parent.window.location.reload();
                    }
                }
            });

            return false;
        });

    });
</script>
</body>
</html>
